﻿#pragma once

#include "SourceCode/Events/MouseEvent.h"
#include "SourceCode/Events/ApplicationEvent.h"
#include "SourceCode/Renderer/OrthoGraphicCamera.h"

namespace Hazal
{
	class COrthographicCameraControll
	{
	public:
		/// <summary>
		/// Constructor
		/// </summary>
		/// <param name="fAspectRatio">屏幕纵横比</param>
		/// <param name="bRotation">是否支持旋转</param>
		COrthographicCameraControll(float fAspectRatio, bool bRotation = false);

		/// <summary>
		/// 屏幕更新响应
		/// </summary>
		/// <param name="fTimeSpan">渲染一帧的时间间隔</param>
		void OnUpdate(float fTimeSpan);

		/// <summary>
		/// 事件响应
		/// </summary>
		/// <param name="e">待响应的事件</param>
		void OnEvent(CEvent& e);

		/// <summary>
		/// 重新计算纵横比
		/// </summary>
		/// <param name="fWidth"></param>
		/// <param name="fHeight"></param>
		void OnResize(float fWidth, float fHeight);

		/// <summary>
		/// inline 获取所控制相机
		/// </summary>
		/// <returns></returns>
		inline const COrthoGraphicCamera& GetCamera() const { return m_camera; }

		/// <summary>
		/// inline 获取所控制相机
		/// </summary>
		/// <returns></returns>
		inline COrthoGraphicCamera& GetCamera() { return m_camera; }

		/// <summary>
		/// inline 设置缩放等级
		/// </summary>
		/// <param name="fZoomLevel">缩放等级</param>
		inline void SetZoomLevel(float fZoomLevel) { m_fZoomLevel = fZoomLevel; }

		/// <summary>
		/// 获取相机当前缩放等级
		/// </summary>
		/// <returns>缩放等级</returns>
		inline float GetZoomLevel() { return m_fZoomLevel; }

	private:
		/// <summary>
		/// 响应鼠标滚轮事件
		/// </summary>
		/// <param name="e">鼠标滚轮事件</param>
		/// <returns></returns>
		bool OnMouseScrolled(CMouseScrolledEvent& e);

		/// <summary>
		/// 响应窗口变化事件
		/// </summary>
		/// <param name="e">窗口变化事件</param>
		/// <returns></returns>
		bool OnWindowResized(CWindowResizeEvent& e);

	private:
		float m_fAspectRatio;
		float m_fZoomLevel = 1.0f;
		bool m_bRotation;

		COrthoGraphicCamera m_camera;

		glm::vec3 m_cameraPos = {0.0f, 0.0f, 0.f};
		float m_fRotationOffset = 0.0f;

		float m_fCameraTranslationSpeed = 1.0f;
		float m_fCameraRotationSpeed = 100.0f;

	};
}